package com.nineclock.document.controller;

import com.nineclock.common.entity.PageResult;
import com.nineclock.common.entity.Result;
import com.nineclock.common.enums.ResponseEnum;
import com.nineclock.document.dto.*;

import com.nineclock.document.service.DocCollaborationsService;
import com.nineclock.document.service.DocFileService;
import com.nineclock.document.service.DocFolderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.sql.ResultSet;
import java.util.List;

@RestController
//@RequestMapping("/document")
@Api(value = "APP文件管理接口", tags = "文档服务")
public class DocumentController {
    @Autowired
    private DocFileService docFileService;
    @Autowired
    private DocFolderService docFolderService;
    @Autowired
    private DocCollaborationsService docCollaborationsService;
    @ApiOperation(value = "查询当前目录下的文件夹及文件")
    @GetMapping("/listFolderAndFile")
    public Result<DocumentDto> queryFolderAndFile(@RequestParam(defaultValue = "0") Long parentFoldId) {
        DocumentDto doc = docFileService.queryFolderAndFile(parentFoldId);
        return Result.success(doc);
    }
    /**
     * 接口名称：新增文件夹
     * 接口路径：POST/document/insertFolder*/
    @PostMapping("insertFolder")
    @ApiOperation(value = "新增文件夹")
    public Result insertFolder(@RequestBody DocFolderDto docFolderDto){
        docFolderService.insertFolder(docFolderDto);
        return Result.success(ResponseEnum.SUCCESS);
    }
    /**
     * 接口名称：根据文档ID查询文档
     * 接口路径：GET/document/getFileByFileId*/
    @GetMapping("getFileByFileId")
    @ApiOperation(value = "根据文档ID查询文档")
    public Result<DocFileDto> getFileByFileId(@RequestParam("id") Long id){
        DocFileDto docFileDto = docFileService.getFileByFileId(id);
        return Result.success(docFileDto);
    }
    /**
     接口名称：查询文档协作者列表
     接口路径：GET/document/pagingCollaborations*/
    @GetMapping("pagingCollaborations")
    @ApiOperation(value = "查询文档协作者列表")
    public Result<PageResult> pagingCollaborations(@RequestParam Long id,@RequestParam(defaultValue = "1") Integer page,@RequestParam(defaultValue = "10") Integer pageSize){
       PageResult pageResult = docCollaborationsService.pagingCollaborations(id,page,pageSize);
       return Result.success(pageResult);
    }
    /**
     * 根据文件ID获取员工列表
     * 接口路径：GET/document/pagingUsers
     */
    @GetMapping("pagingUsers")
    @ApiOperation("根据文件ID获取员工列表")
    public Result<List<DocUserCollaborationDTO>> queryUsers(Long id){
        List<DocUserCollaborationDTO> dtoList = docFileService.queryUsers(id);
        return Result.success(dtoList);
    }
}
